package version2024.easy;

import java.util.Scanner;

/**
 * @author sunhl
 * @Description: HJ35 蛇形矩阵
 * @Date: created in 2025/1/14 星期二 16:58
 * @Modified By:
 */
public class HJ35_SerpentMatrix {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            //读入正整数n
            int n = in.nextInt();

            //    result[0][0]
            // -> result[1][0] -> result[0][1]
            // -> result[2][0] -> result[1][1] -> result[0][2]
            //建立数组（n行）
            int[][] result = new int[n][];
            //记录依次赋予的数组值
            int t = 1;

            for (int i = 0; i < n; i++) {
                //数组第i行有n-i个元素
                result[i] = new int[n - i];
                for (int j = 0; j < i + 1; j++) {
                    result[i - j][j] = t;
                    t++;
                }
            }

            //输出数组值
            for (int[] a : result) {
                for (int a1 : a)
                    System.out.print(a1 + " ");
                System.out.println();
            }
        }
    }
}
